//
//  JYCommitOrderController.m
//  JYFarm
//
//  Created by 花花 on 2017/10/17.
//  Copyright © 2017年 花花. All rights reserved.
//

#import "JYCommitOrderController.h"
#import "JYOrderDetaCell.h"
#import "JYOrderInfoCell.h"
#import "JYPaymentController.h"
@interface JYCommitOrderController ()
@property(nonatomic)JYOrderDetaView *detaView;

@property(nonatomic)NSArray *detaArr;

@property(nonatomic)NSArray *titleArr;
@end

static NSString *const CommitOrderCellID = @"CommitOrderCellID";
@implementation JYCommitOrderController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"提交订单";
    [self setupTableView];
    
    [self setupBottomView];
}
#pragma mark - setupTableView
- (void)setupTableView{
    
    
    self.tableView.tableHeaderView = self.detaView;
    [self.tableView registerClass:[JYOrderDetaCell class] forCellReuseIdentifier:CommitOrderCellID];
    self.detaView.dataArr = self.detaArr;
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 54, 0);
    self.tableView.tableFooterView = [UIView new];


}
- (void)setupBottomView{
    
    UIView *bottomView = [UIView new];
    bottomView.backgroundColor = k9Color;
    [self.view addSubview:bottomView];
    JYWeakSelf;
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.view.mas_left);
        make.right.mas_equalTo(weakSelf.view.mas_right);
        make.height.mas_equalTo(54);
        make.bottom.mas_equalTo(weakSelf.view.mas_bottom);
        
    }];

    UILabel *leftLabel = [UILabel labelText:@"￥6686.00" fontSize:15 textColor:kfColor textAlignment:NSTextAlignmentLeft];
    [bottomView addSubview:leftLabel];
    [leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(13);
        make.centerY.mas_equalTo(bottomView.mas_centerY);
        make.width.mas_equalTo(Screen_Width -125);
        
    }];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:@"提交订单" forState:UIControlStateNormal];
    [btn setTitleColor:kfColor forState:UIControlStateNormal];
    [btn setBackgroundColor:kThemeColor];
    [btn addTarget:self action:@selector(commitOrderOnClick) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(leftLabel.mas_right);
        make.right.mas_equalTo(bottomView.mas_right);
        make.height.mas_equalTo(bottomView.mas_height);
        make.bottom.mas_equalTo(bottomView.mas_bottom);
        
    }];
    

}
- (void)commitOrderOnClick{

    [self.navigationController pushViewController:[JYPaymentController new] animated:YES];
    

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 2;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0) {
        return 1;
    }
    return self.titleArr.count;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 10;
    
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 0){
        
        return 66;
    }
    return kTableView_rowHeight;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    JYOrderDetaCell *cell = [tableView dequeueReusableCellWithIdentifier:CommitOrderCellID];
    
    if (indexPath.section == 0) {
        cell.leftLabel.numberOfLines = 0;
        cell.leftLabel.text = @"沈笑 13632200000\n上海市闵行区龙湖天街d栋701（龙门客栈)";
        cell.rightLabel.text = @"";
        cell.backgroundColor = [UIColor whiteColor];
     
    }else{
     
        
        cell.leftLabel.text = [self.titleArr safeObjectAtIndex:indexPath.row];
        cell.rightLabel.text = @" -¥20.00";
        if (indexPath.row==1) {
            cell.rightLabel.textColor = [UIColor colorWithHexString:@"EF216B"];
            cell.rightLabel.text = @"-¥20.00";
        }else if (indexPath.row == 4) {
            cell.leftLabel.textColor = [UIColor colorWithHexString:@"EF216B"];
            cell.backgroundColor = [UIColor colorWithHexString:@"F2F2F2"];
            cell.rightLabel.text = @"";
            
        }
    }
    return cell;
}

#pragma mark - SEL Methods
- (void)payOnClick{
    
    NSLog(@"确认支付");
    
    
    
}
#pragma mark - Setter && Getter Methods
- (JYOrderDetaView *)detaView{
    
    if (!_detaView) {
        _detaView = [[JYOrderDetaView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 360)];
        _detaView.isCommitOrder = YES;
    }
    return _detaView;
    
}
- (NSArray *)detaArr{
    
    if (!_detaArr) {
        _detaArr = @[@"12",@"232",@"12",@"232",@"12",@"232",@"12",@"232",@"12",@"232",@"12",@"232",@"12",@"232",@"12",@"232"];
    }
    return _detaArr;
    
}

- (NSArray *)titleArr{
    
    if (!_titleArr) {
        _titleArr = @[@"配送费",@"运费减免",@"押金",@"总计金额",@"注: 此次付款需补差上次订单欠款"];
    }
    return _titleArr;
    
}




@end
